import request from "@/utils/request";

//获取短信验证码   /app/v1_0/sms/codes/:mobile   get
export const codeApi = mobile => {
  // return request(`/app/v1_0/sms/codes/${mobile}`);
  return request(`/v1_0/sms/codes/${mobile}`);
};

//用户认证（登录注册）  /app/v1_0/authorizations
export const loginApi = obj => {
  // return request.post(`/app/v1_0/authorizations`, obj);
  return request.post(`/v1_0/authorizations`, obj);
};

//获取用户自己信息   /app/v1_0/user
export const userApi = obj => {
  // return request("/app/v1_0/user");
  return request("/v1_0/user");
};

//获取用户频道列表   /app/v1_0/user/channels
export const channelsApi = obj => {
  return request("/v1_0/user/channels");
};

//  频道新闻推荐_V1.1   /v1_1/articles
export const articlesApi = obj => {
  return request("/v1_1/articles", {
    params: {
      channel_id: obj.channel_id,
      timestamp: obj.timestamp,
      with_top: obj.with_top
    }
  });
};

//全部频道列表数据   /app/v1_0/channels
export const allchannelsApi = obj => {
  return request(`/v1_0/channels`);
};

//删除指定用户频道    /app/v1_0/user/channels/:target
//target用户频道id  channel
export const delchannelsApi = channelId => {
  return request({
    method: "DELETE",
    url: `/v1_0/user/channels/${channelId}`
  });
};

//获取联想建议（自动补全）  搜索建议    /app/v1_0/suggestion
export const getSearchSuggestionsApi = q => {
  return request(`/v1_0/suggestion`, {
    params: {
      q
    }
  });
};

//获取搜索结果   /v1_0/search
export const getsearchresultApi = params => {
  return request(`/v1_0/search`, {
    params: {
      page: params.page,
      per_page: params.per_page,
      q: params.q
    }
  });
};
/**
 * 获取文章   /app/v1_0/articles/:article_id
 */
export const getArticleByIdApi = articleId => {
  return request({
    method: "GET",
    url: `/v1_0/articles/${articleId}`
  });
};

//收藏文章   /app/v1_0/article/collections
export const collectionsApi = str => {
  return request({
    method: "post",
    url: `/v1_0/article/collections`,
    data: {
      target: str
    }
  });
};

//取消收藏文章  /app/v1_0/article/collections/:target
export const delcollectionsApi = obj => {
  return request({
    method: "DELETE",
    url: `/v1_0/article/collections/${obj}`
  });
};

//对文章点赞   /app/v1_0/article/likings      POST
export const likearticleApi = str => {
  return request({
    method: "post",
    url: `/v1_0/article/likings`,
    data: {
      target: str
    }
  });
};

//取消文章点赞  /v1_0/article/likings/:target

export const dellikearticleApi = obj => {
  return request({
    method: "DELETE",
    url: `/v1_0/article/likings/${obj}`
  });
};

//关注用户      /app/v1_0/user/followings        POST
export const followingsApi = str => {
  return request({
    method: "post",
    url: `/v1_0/user/followings `,
    data: {
      target: str
    }
  });
};
